package metalink.admin;

import java.sql.*;


import java.util.ArrayList;

import model.admin.QBColumnName;
import myutil.Connect;

import com.opensymphony.xwork2.ActionSupport;

public class QueryBuilder extends ActionSupport{
	
	private String menu, table, colum_name;
	private String [] target;
	
	private ArrayList<QBColumnName> columns = new ArrayList<QBColumnName>();
	
	
	public String getMenu() {
		return menu;
	}

	public void setMenu(String menu) {
		this.menu = menu;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public void setColumns(ArrayList<QBColumnName> columns) {
		this.columns = columns;
	}




	public ArrayList<QBColumnName> getColumns() {
		return columns;
	}

	
	public String execute() {
		
		try {
			
			Connect c = new Connect();
			if(menu.equalsIgnoreCase("01")){
				setTable("batch_details");
			}
			else if(menu.equalsIgnoreCase("02")){
				setTable("course_details");
			}
			else if(menu.equalsIgnoreCase("03")){
				setTable("department_details");
			}
			else if(menu.equalsIgnoreCase("04")){
				setTable("degree_details");
			}
			else if(menu.equalsIgnoreCase("05")){
				setTable("student_details");
			}
			else if(menu.equalsIgnoreCase("06")){
				setTable("college_staff");
			}
			else if(menu.equalsIgnoreCase("07")){
				setTable("college_residential");
			}
			else if(menu.equalsIgnoreCase("08")){
				setTable("library_book_details");
			}
			else if(menu.equalsIgnoreCase("09")){
				setTable("placements");
			}
			ResultSet rs = c.getResult("select * from " + table);
			ResultSetMetaData rsmd = rs.getMetaData();
			int num = rsmd.getColumnCount();
			for(int i=1; i<=num; i++){
				QBColumnName bean = new QBColumnName(i, rsmd.getColumnName(i));
				columns.add(bean);
			}
			
			return SUCCESS;
		}	catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}

	public String getColum_name() {
		return colum_name;
	}

	public void setColum_name(String colum_name) {
		this.colum_name = colum_name;
	}

	public String[] getTarget() {
		return target;
	}

	public void setTarget(String[] target) {
		this.target = target;
	}


}
